<!--
  User: Kuttubek Aidaraliev
  Date: 06.04.2010
  Time: 16:13:37
-->
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    template="../../WEB-INF/jspx/common/template.xhtml">

    <ui:define name="head">
      <title>
          <h:outputText value="#{messages.creatingVacancy}" rendered="#{vacancyBeanController.newEntity}"/>
          <h:outputText value="#{messages.editingVacancy}" rendered="#{!vacancyBeanController.newEntity}"/>
      </title>
  </ui:define>
  <ui:define name="body">
        <h:panelGroup rendered="#{vacancyBeanController.newEntity}">
            <h3 align="center"><h:outputText value="#{messages.creatingVacancy}" /></h3>
        </h:panelGroup>
        <h:panelGroup rendered="#{!vacancyBeanController.newEntity}">
            <h3 align="center"><h:outputText value="#{messages.editingVacancy}" /></h3>
        </h:panelGroup>
        <h:form>
            <rich:tabPanel switchType="client">
                <rich:tab label="#{messages.overview}">
                    <a4j:region>
                    <h:panelGrid columns="2">
                        <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.number}" id="numberLabel" /></ui:define>
                                <h:inputText id="number" required="true" requiredMessage="#{messages.requiedMessage}"
                                    value="#{vacancyBeanController.entity.number}" rendered="#{vacancyBeanController.editField}"/>
                            <ui:param name="required" value="true"/>
                            <ui:param name="idInput" value="number"/>
                            <ui:param name="value" value="#{vacancyBeanController.entity.number}"/>
                            <ui:param name="editField" value="#{vacancyBeanController.editField}"/>
                        </ui:decorate>

                        <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.title}" id="titleLabel" /></ui:define>
                                <h:inputText id="title" required="true" requiredMessage="#{messages.requiedMessage}"
                                    value="#{vacancyBeanController.entity.title}" rendered="#{vacancyBeanController.editField}"/>
                            <ui:param name="required" value="true"/>
                            <ui:param name="idInput" value="title"/>
                            <ui:param name="value" value="#{vacancyBeanController.entity.title}"/>
                            <ui:param name="editField" value="#{vacancyBeanController.editField}"/>
                        </ui:decorate>

                        <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.customer}"/></ui:define>
                            <h:selectOneMenu id="customer" required="true" requiredMessage="#{messages.requiedMessage}"
                                value="#{vacancyBeanController.entity.customer}" rendered="#{vacancyBeanController.editField}">
                                <f:selectItems value="#{customerBeanController.selectList}"/>
                                <f:converter converterId="customerConverter"/>
                            </h:selectOneMenu>
                            <ui:param name="required" value="true"/>
                            <ui:param name="idInput" value="customer"/>
                            <ui:param name="value" value="#{vacancyBeanController.entity.customer.officialName}"/>
                            <ui:param name="editField" value="#{vacancyBeanController.editField}"/>
                        </ui:decorate>

                        <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.datePublish}" id="datePublishLabel" /></ui:define>
                                <rich:calendar id="datePublish" required="true" requiredMessage="#{messages.requiedMessage}"
                                    value="#{vacancyBeanController.entity.datePublish}" rendered="#{vacancyBeanController.editField}"/>
                            <ui:param name="required" value="true"/>
                            <ui:param name="idInput" value="datePublish"/>
                            <ui:param name="value" value="#{vacancyBeanController.entity.datePublish}"/>
                            <ui:param name="editField" value="#{vacancyBeanController.editField}"/>
                            <ui:param name="myConverter" value="#{baseDateConverterBean}"/>
                        </ui:decorate>

                        <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.appearance}"/></ui:define>
                            <h:selectOneMenu id="appearance" required="true" requiredMessage="#{messages.requiedMessage}"
                                value="#{vacancyBeanController.entity.appearance}" rendered="#{vacancyBeanController.editField}">
                                <f:selectItems value="#{vacancyBeanController.appearanceSelectItems}"/>
                                <f:converter converterId="appearanceEnumConverter"/>
                            </h:selectOneMenu>
                            <ui:param name="required" value="true"/>
                            <ui:param name="idInput" value="appearance"/>
                            <ui:param name="value" value="#{vacancyBeanController.entity.appearance}"/>
                            <ui:param name="editField" value="#{vacancyBeanController.editField}"/>
                            <ui:param name="myConverter" value="#{enumAsStringConverterBean}"/>
                        </ui:decorate>
                        
                    </h:panelGrid>
                    <!--<rich:panel>-->
                        <h:panelGrid columns="3">
                            <h:panelGroup rendered="#{vacancyBeanController.editField}">
                                <h:outputText value="#{messages.targetDate}" />
                                <h:outputLabel styleClass="required">*</h:outputLabel>
                            </h:panelGroup>
                            <a4j:outputPanel id="targetDateAjaxPanel" ajaxRendered="true">
                                <h:inputText id="count" required="true" requiredMessage="#{messages.requiedMessage}"
                                    value="#{vacancyBeanController.entity.targetDate.count}" rendered="#{vacancyBeanController.editField}">
                                    <a4j:support ajaxSingle="true" actionListener="#{vacancyBeanController.changeTargetDateForParam}"
                                                 event="onkeyup" reRender="targetDateAjaxPanel"/>
                                </h:inputText>
                                <h:selectOneMenu id="time" required="true" requiredMessage="#{messages.requiedMessage}"
                                        value="#{vacancyBeanController.entity.targetDate.time}" rendered="#{vacancyBeanController.editField}">
                                    <f:selectItems value="#{vacancyBeanController.timeSelectItems}"/>
                                    <f:converter converterId="timeEnumConverter"/>
                                    <a4j:support ajaxSingle="true" actionListener="#{vacancyBeanController.changeTargetDateForParam}"
                                                 event="onchange" reRender="targetDateAjaxPanel"/>
                                </h:selectOneMenu>
                                <h:panelGroup>
                                    <h:outputText value="#{messages.closeUp}" style="font-weight:bold;"/>
                                    <h:outputLabel styleClass="required" rendered="#{vacancyBeanController.editField}">*</h:outputLabel>
                                </h:panelGroup>
                                <rich:spacer width="15"/>
                                <rich:calendar id="closeUp" value="#{vacancyBeanController.entity.targetDate.closeUp}"
                                               rendered="#{vacancyBeanController.editField}"/>
                                <h:outputText value="#{vacancyBeanController.entity.targetDate.closeUp}"
                                              rendered="#{not vacancyBeanController.editField}" />
                                <h:panelGroup>
                                    <rich:message for="count" styleClass="errors">
                                        <f:facet name="errorMarker">
                                            <h:graphicImage value="/img/error.gif"/>
                                        </f:facet>
                                    </rich:message>
                                    <rich:message for="time" styleClass="errors">
                                        <f:facet name="errorMarker">
                                            <h:graphicImage value="/img/error.gif"/>
                                        </f:facet>
                                    </rich:message>
                                    <rich:message for="closeUp" styleClass="errors">
                                        <f:facet name="errorMarker">
                                            <h:graphicImage value="/img/error.gif"/>
                                        </f:facet>
                                    </rich:message>
                                </h:panelGroup>
                            </a4j:outputPanel>
                        </h:panelGrid>
                    <!--</rich:panel>-->
                    <h:panelGrid columns="2">
                        <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.state}"/></ui:define>
                            <h:selectOneMenu id="state" required="true" requiredMessage="#{messages.requiedMessage}"
                                value="#{vacancyBeanController.entity.state}" rendered="#{vacancyBeanController.editField}">
                                <f:selectItems value="#{vacancyBeanController.stateSelectItems}"/>
                                <f:converter converterId="stateEnumConverter"/>
                                <a4j:support action="#{vacancyBeanController.changeState}" ajaxSingle="true" event="onchange" reRender="closingDateAjaxPanel"/>
                            </h:selectOneMenu>
                            <ui:param name="required" value="true"/>
                            <ui:param name="idInput" value="state"/>
                            <ui:param name="value" value="#{vacancyBeanController.entity.state}"/>
                            <ui:param name="editField" value="#{vacancyBeanController.editField}"/>
                            <ui:param name="myConverter" value="#{enumAsStringConverterBean}"/>
                        </ui:decorate>

                        <a4j:outputPanel id="closingDateAjaxPanel" ajaxRendered="true">
                            <h:panelGroup rendered="#{vacancyBeanController.closed}">
                               <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                                    <ui:define name="label">
                                        <h:outputText value="#{messages.closingDate}"
                                            id="closingDateLabel" rendered="#{vacancyBeanController.closed}" converter="baseDateConverter" />
                                    </ui:define>
                                    <rich:spacer width="15"/>
                                    <rich:calendar id="closingDate" required="false" requiredMessage="#{messages.requiedMessage}"
                                        value="#{vacancyBeanController.entity.closingDate}" rendered="#{vacancyBeanController.closed and vacancyBeanController.editField}"/>
                                    <ui:param name="required" value="false"/>
                                    <ui:param name="idInput" value="closingDate"/>
                                    <ui:param name="value" value="#{vacancyBeanController.entity.closingDate}"/>
                                    <ui:param name="editField" value="#{vacancyBeanController.editField}"/>
                               </ui:decorate>
                            </h:panelGroup>
                        </a4j:outputPanel>
                        <h:panelGroup />

                        <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.categorySelection}"/></ui:define>
                            <h:selectOneMenu id="categorySelection" required="true" requiredMessage="#{messages.requiedMessage}"
                                value="#{vacancyBeanController.entity.categorySelection}" rendered="#{vacancyBeanController.editField}">
                                <f:selectItems value="#{vacancyBeanController.categorySelectionSelectItems}"/>
                                <f:converter converterId="categorySelectionEnumConverter"/>
                            </h:selectOneMenu>
                            <ui:param name="required" value="true"/>
                            <ui:param name="idInput" value="categorySelection"/>
                            <ui:param name="value" value="#{vacancyBeanController.entity.categorySelection}"/>
                            <ui:param name="editField" value="#{vacancyBeanController.editField}"/>
                            <ui:param name="myConverter" value="#{enumAsStringConverterBean}"/>
                        </ui:decorate>

                        <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.complexity}"/></ui:define>
                            <h:selectOneMenu id="complexity" required="true" requiredMessage="#{messages.requiedMessage}"
                                value="#{vacancyBeanController.entity.complexity}" rendered="#{vacancyBeanController.editField}">
                                <f:selectItems value="#{vacancyBeanController.complexitySelectItems}"/>
                                <f:converter converterId="javax.faces.Integer"/>
                            </h:selectOneMenu>
                            <ui:param name="required" value="true"/>
                            <ui:param name="idInput" value="complexity"/>
                            <ui:param name="value" value="#{vacancyBeanController.entity.complexity}"/>
                            <ui:param name="editField" value="#{vacancyBeanController.editField}"/>
                        </ui:decorate>

                        <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.priority}"/></ui:define>
                            <h:selectOneMenu id="priority" required="true" requiredMessage="#{messages.requiedMessage}"
                                value="#{vacancyBeanController.entity.priority}" rendered="#{vacancyBeanController.editField}">
                                <f:selectItems value="#{vacancyBeanController.prioritySelectItems}"/>
                                <f:converter converterId="javax.faces.Integer"/>
                            </h:selectOneMenu>
                            <ui:param name="required" value="true"/>
                            <ui:param name="idInput" value="priority"/>
                            <ui:param name="value" value="#{vacancyBeanController.entity.priority}"/>
                            <ui:param name="editField" value="#{vacancyBeanController.editField}"/>
                        </ui:decorate>

                        <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.salary}" id="salaryLabel" /></ui:define>
                                <h:inputText id="salary" required="true" requiredMessage="#{messages.requiedMessage}"
                                    value="#{vacancyBeanController.entity.salary}" rendered="#{vacancyBeanController.editField}">
                                    <f:validateDoubleRange minimum="0.0"/>
                                </h:inputText>
                            <ui:param name="required" value="true"/>
                            <ui:param name="idInput" value="salary"/>
                            <ui:param name="value" value="#{vacancyBeanController.entity.salary}"/>
                            <ui:param name="editField" value="#{vacancyBeanController.editField}"/>
                        </ui:decorate>

                        <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.from}" id="fromLabel" /></ui:define>
                                <h:inputText id="from" required="true" requiredMessage="#{messages.requiedMessage}"
                                    value="#{vacancyBeanController.entity.levelSalary.from}" rendered="#{vacancyBeanController.editField}">
                                    <f:validateDoubleRange minimum="0.0"/>
                                </h:inputText>
                            <ui:param name="required" value="true"/>
                            <ui:param name="idInput" value="from"/>
                            <ui:param name="value" value="#{vacancyBeanController.entity.levelSalary.from}"/>
                            <ui:param name="editField" value="#{vacancyBeanController.editField}"/>
                        </ui:decorate>

                        <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.to}" id="toLabel" /></ui:define>
                                <h:inputText id="to" required="true" requiredMessage="#{messages.requiedMessage}"
                                    value="#{vacancyBeanController.entity.levelSalary.to}" rendered="#{vacancyBeanController.editField}">
                                    <f:validateDoubleRange minimum="0.0"/>
                                </h:inputText>
                            <ui:param name="required" value="true"/>
                            <ui:param name="idInput" value="to"/>
                            <ui:param name="value" value="#{vacancyBeanController.entity.levelSalary.to}"/>
                            <ui:param name="editField" value="#{vacancyBeanController.editField}"/>
                        </ui:decorate>

                        <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.specialty}" id="specialtyLabel" /></ui:define>
                                <h:inputText id="specialty" required="true" requiredMessage="#{messages.requiedMessage}"
                                    value="#{vacancyBeanController.entity.specialty}" rendered="#{vacancyBeanController.editField}">
                                    <f:validateLength minimum="1" maximum="100"/>
                                </h:inputText>
                            <ui:param name="required" value="true"/>
                            <ui:param name="idInput" value="specialty"/>
                            <ui:param name="value" value="#{vacancyBeanController.entity.specialty}"/>
                            <ui:param name="editField" value="#{vacancyBeanController.editField}"/>
                        </ui:decorate>

                        <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.applicant}"/></ui:define>
                            <h:selectOneMenu id="applicant" required="true" requiredMessage="#{messages.requiedMessage}"
                                value="#{vacancyBeanController.entity.applicant}" rendered="#{vacancyBeanController.editField}">
                                <f:selectItems value="#{applicantBeanController.selectList}"/>
                                <f:converter converterId="applicantConverter"/>
                            </h:selectOneMenu>
                            <ui:param name="required" value="true"/>
                            <ui:param name="idInput" value="applicant"/>
                            <ui:param name="value" value="#{vacancyBeanController.entity.applicant.title}"/>
                            <ui:param name="editField" value="#{vacancyBeanController.editField}"/>
                        </ui:decorate>

                        <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.sourceSelection}"/></ui:define>
                            <h:selectOneMenu id="sourceSelection" required="true" requiredMessage="#{messages.requiedMessage}"
                                value="#{vacancyBeanController.entity.channelSelection}" rendered="#{vacancyBeanController.editField}">
                                <f:selectItems value="#{vacancyBeanController.channelSelectionSelectItems}"/>
                                <f:converter converterId="channelSelectionEnumConverter"/>
                            </h:selectOneMenu>
                            <ui:param name="required" value="true"/>
                            <ui:param name="idInput" value="sourceSelection"/>
                            <ui:param name="value" value="#{vacancyBeanController.entity.channelSelection}"/>
                            <ui:param name="editField" value="#{vacancyBeanController.editField}"/>
                            <ui:param name="myConverter" value="#{enumAsStringConverterBean}"/>
                        </ui:decorate>

                        <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.additionalInformation}" id="additionalInformationLabel" /></ui:define>
                                <h:inputTextarea id="additionalInformation" required="true" requiredMessage="#{messages.requiedMessage}"
                                    value="#{vacancyBeanController.entity.additionalInformation}" rendered="#{vacancyBeanController.editField}">
                                    <f:validateLength minimum="1" maximum="10000"/>
                                </h:inputTextarea>
                            <ui:param name="required" value="true"/>
                            <ui:param name="idInput" value="additionalInformation"/>
                            <ui:param name="value" value="#{vacancyBeanController.entity.additionalInformation}"/>
                            <ui:param name="editField" value="#{vacancyBeanController.editField}"/>
                        </ui:decorate>
                    </h:panelGrid>

                    <a4j:region>
                        <a4j:commandLink ajaxSingle="true" id="editContactPersons" action="#{vacancyBeanController.preEditingContactPersons}">
                            <h:outputText value="#{messages.edit}" />
                        </a4j:commandLink>
                    </a4j:region>

                    <a4j:outputPanel ajaxRendered="true">
                         <ui:include src="../../layout/selectContactPerson.xhtml">
                            <ui:param name="controller" value="#{vacancyBeanController}"/>
                            <ui:param name="selectList" value="#{contactPersonBeanController.selectList}"/>
                         </ui:include>
                    </a4j:outputPanel>

                    <ui:decorate template="../../WEB-INF/jspx/contactPerson/contactPersonTable.xhtml">
                        <ui:param name="contactPersons" value="#{vacancyBeanController.entity.contactPersons}"/>
                        <ui:param name="id" value="contactPersonTable"/>
                    </ui:decorate>

                    <a4j:commandButton value="#{messages.update}" action="#{customerBeanController.updated}"
                             rendered="#{!vacancyBeanController.newEntity and vacancyBeanController.editField}"/>
                    <rich:spacer width="10" rendered="#{!vacancyBeanController.newEntity and vacancyBeanController.editField}"/>
                    <a4j:commandButton value="#{messages.cancel}" action="#{vacancyBeanController.cancel}"
                             rendered="#{!vacancyBeanController.newEntity and vacancyBeanController.editField}"/>
                    <a4j:commandButton value="#{messages.edit}" action="#{vacancyBeanController.preUpdate}"
                             rendered="#{!vacancyBeanController.newEntity and not vacancyBeanController.editField}"
                             immediate="true"/>

                </a4j:region>

                </rich:tab>
                <rich:tab>

                </rich:tab>
                <rich:tab>
                    
                </rich:tab>
            </rich:tabPanel>

            <h:commandButton value="#{messages.create}" id="create" action="#{vacancyBeanController.inserted}"
                             rendered="#{vacancyBeanController.newEntity}" />
            <a4j:commandButton value="#{messages.cancel}" id="cancel" action="#{vacancyBeanController.cancel}"
                             rendered="#{vacancyBeanController.newEntity}" ajaxSingle="true" />

        </h:form>
  </ui:define>
</ui:composition>